<template>
  <div>
    <router-link tag="div" to="/" class="header-abs" v-show="absShow">
      <span class="iconfont backicon">&#xe624;</span>
    </router-link>
    <div class="header-fixed" v-show="!absShow" :style="headerFixedShow">
      <router-link to="/" class="iconfont header-fixed-back">&#xe624;</router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      absShow: true,
      headerFixedShow: {
        opacity: 0
      }
    }
  },
  methods: {
    handleAbsShow () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        this.absShow = false
        let opacity = top / 160
        opacity = opacity > 1 ? 1 : opacity
        this.headerFixedShow = {
          opacity: opacity
        }
      } else {
        this.absShow = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleAbsShow)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleAbsShow)
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl";
  .header-abs
    position: absolute;
    top: .2rem;
    left: .2rem;
    width: .8rem;
    height: .8rem;
    border-radius: .4rem;
    background: rgba(0, 0, 0, .6);
    line-height: .8rem;
    text-align: center;
    .backicon
      font-size: .4rem;
      color: #fff;
  .header-fixed
    z-index: 2;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    overflow: hidden;
    height: $headerHeight;
    line-height: $headerHeight;
    text-align: center;
    color: #fff;
    background: $bgcolor;
    font-size: .32rem;
    .header-fixed-back
      position: absolute;
      font-size: .36rem;
      width: .64rem;
      height: $headerHeight;
      line-height: $headerHeight;
      left: 0;
      color: #fff;
</style>
